package cn.yanghan.interceptor;

import cn.yanghan.domain.LoginUser;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

public class conText {

    public static LoginUser getLoginUser(){
        //获取登录用户
        SecurityContext securityContext = SecurityContextHolder.getContext();
        Authentication authentication = securityContext.getAuthentication();
        if(authentication!=null){
            String principal = (String) authentication.getPrincipal();
            LoginUser loginUser = JSON.parseObject(principal, LoginUser.class);
            return loginUser;
        }
        return null;
    }
}
